import os
import pandas as pd
from quant_researcher.quant.datasource_fetch.crypto_api.okex.okex import fetch_okex_margin_interest_rate
from utils import df_into_db

DATA_DIR = f'E:\\指标数据'  # 用于存放测试数据

# 分析okx杠杆交易费率
okex_margin_interest_rate = fetch_okex_margin_interest_rate()
file_path = os.path.join(DATA_DIR, f'margin_interest_rate')
file_name = os.path.join(file_path, f'okx_margin_interest_rate.xlsx')
if os.path.exists(file_name):
    historical_data = pd.read_excel(file_name)
    if max(historical_data['end_date']) < max(okex_margin_interest_rate['end_date']):
        all_df = pd.concat([historical_data, okex_margin_interest_rate], axis=0, ignore_index=True)
    else:
        pass
all_df = all_df[~all_df.duplicated(subset='end_date')]  # 一天可能有多个费率数据

df_into_db(all_df, db_name="margin_interest_rate", table_name="okx_margin_interest_rate")
print("stop")